package com.example.redis.job;

import com.example.redis.dto.FundSearchDto;
import com.example.redis.service.IFundWarmUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class FundWarmUpJob {
    @Autowired
    private IFundWarmUpService fundWarmUpService;

    @Autowired
    private StringRedisTemplate template;

    @Scheduled(cron = "0 09 23 * * ?") //每天零点调整任务 0 0 0 * * ?
    public void  doWork(){
        System.out.println("定时任务:测试调整任务");
        //1.清理redis历史数据
        template.opsForHash().delete("fundList","allFundByfund_codeAsc");
        template.opsForHash().delete("fundList","allFundByfund_codeDesc");
        template.opsForHash().delete("fundList","allFundByfund_short_nameAsc");
        template.opsForHash().delete("fundList","allFundByfund_short_nameDesc");
        template.opsForHash().delete("fundList","allFundByend_dateAsc");
        template.opsForHash().delete("fundList","allFundByend_dateDesc");
        template.opsForHash().delete("fundList","allFundByunit_net_valAsc");
        template.opsForHash().delete("fundList","allFundByunit_net_valDesc");

        template.opsForHash().delete("voList","allFundByfund_codeAsc");
        template.opsForHash().delete("voList","allFundByfund_codeDesc");
        template.opsForHash().delete("voList","allFundByfund_short_nameAsc");
        template.opsForHash().delete("voList","allFundByfund_short_nameDesc");
        template.opsForHash().delete("voList","allFundByend_dateAsc");
        template.opsForHash().delete("voList","allFundByend_dateDesc");
        template.opsForHash().delete("voList","allFundByunit_net_valAsc");
        template.opsForHash().delete("voList","allFundByunit_net_valDesc");

        //2.从MySql中获取 基金列表
        //3. 把基金数据存到redis中
        FundSearchDto allFundByFundCodeAsc = fundWarmUpService.getAllFund("fund_code", "Asc");
        FundSearchDto allFundByFundCodeDesc = fundWarmUpService.getAllFund("fund_code", "Desc");
        FundSearchDto allFundByFundShortNameAsc = fundWarmUpService.getAllFund("fund_short_name", "Asc");
        FundSearchDto allFundByFundShortNameDesc = fundWarmUpService.getAllFund("fund_short_name", "Desc");
        FundSearchDto allFundByEndDateAsc = fundWarmUpService.getAllFund("end_date", "Asc");
        FundSearchDto allFundByEndDateDesc = fundWarmUpService.getAllFund("end_date", "Desc");
        FundSearchDto allFundByUnitNetValAsc = fundWarmUpService.getAllFund("unit_net_val", "Asc");
        FundSearchDto allFundByUnitNetValDesc = fundWarmUpService.getAllFund("unit_net_val", "Desc");


//        template.opsForHash().put("fundList","allFundByfund_codeAsc",allFundByFundCodeAsc.getFundList());
//        template.opsForHash().put("fundList","allFundByfund_codeDesc",allFundByFundCodeDesc.getFundList());
//        template.opsForHash().put("fundList","allFundByfund_short_nameAsc",allFundByFundShortNameAsc.getFundList());
//        template.opsForHash().put("fundList","allFundByfund_short_nameDesc",allFundByFundShortNameDesc.getFundList());
//        template.opsForHash().put("fundList","allFundByend_dateAsc",allFundByEndDateAsc.getFundList());
//        template.opsForHash().put("fundList","allFundByend_dateDesc",allFundByEndDateDesc.getFundList());
//        template.opsForHash().put("fundList","allFundByunit_net_valAsc",allFundByUnitNetValAsc.getFundList());
//        template.opsForHash().put("fundList","allFundByunit_net_valDesc",allFundByUnitNetValDesc.getFundList());
//
//        template.opsForHash().put("voList","allFundByfund_codeAsc",allFundByFundCodeAsc.getVoList());
//        template.opsForHash().put("voList","allFundByfund_codeDesc",allFundByFundCodeDesc.getVoList());
//        template.opsForHash().put("voList","allFundByfund_short_nameAsc",allFundByFundShortNameAsc.getVoList());
//        template.opsForHash().put("voList","allFundByfund_short_nameDesc",allFundByFundShortNameDesc.getVoList());
//        template.opsForHash().put("voList","allFundByend_dateAsc",allFundByEndDateAsc.getVoList());
//        template.opsForHash().put("voList","allFundByend_dateDesc",allFundByEndDateDesc.getVoList());
//        template.opsForHash().put("voList","allFundByunit_net_valAsc",allFundByUnitNetValAsc.getVoList());
//        template.opsForHash().put("voList","allFundByunit_net_valDesc",allFundByUnitNetValDesc.getVoList());

    }
}
